﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NutriLeaf.Web.Core.Food
{
    public class IUserFoodIngredientFavs
    {
        void AddFoodIngredientToUserFavs(int userId, int foodIngredientId, ref NutriLeaf.Web.Model.NutriLeafDBEntities context) {

            Model.UserFoodIngredientFav fav = new Model.UserFoodIngredientFav();
            fav.UserID = userId;
            fav.FoodIngredientID = foodIngredientId;
            context.UserFoodIngredientFavs.AddObject(fav);
            context.SaveChanges();
        }

        void RemoveFoodIngredientFromUserFavs(int userId, int foodIngredientId, ref NutriLeaf.Web.Model.NutriLeafDBEntities context) {
           context.DeleteObject(context.UserFoodIngredientFavs.Where(p => p.FoodIngredientID == foodIngredientId && p.UserID == userId).First());
           context.SaveChanges();
        }

        void RemoveFoodIngredientFromUserFavs(int userFoodIngredientFavsId, ref NutriLeaf.Web.Model.NutriLeafDBEntities context) {

            context.DeleteObject(context.UserFoodIngredientFavs.Where(p => p.UserFoodIngredientFavsID == userFoodIngredientFavsId).First());
            context.SaveChanges();
        }

        List<Model.FoodIngredient> GetAllUserFavsFoodIngredients(int userId, ref NutriLeaf.Web.Model.NutriLeafDBEntities context) {
            return context.FoodIngredients.Where(p => p.UserID == userId ).ToList();

        }
    }
}